package com.ruoyi.project.system.relevantimg.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.relevantimg.domain.RelevantImg;
import com.ruoyi.project.system.relevantimg.service.IRelevantImgService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 相关图片Controller
 * 
 * @author LCL
 * @date 2020-12-10
 */
@Controller
@RequestMapping("/system/relevantimg")
public class RelevantImgController extends BaseController
{
    private String prefix = "system/relevantimg";

    @Autowired
    private IRelevantImgService relevantImgService;

    @RequiresPermissions("system:relevantimg:view")
    @GetMapping()
    public String relevantimg()
    {
        return prefix + "/relevantimg";
    }

    /**
     * 查询相关图片列表
     */
    @RequiresPermissions("system:relevantimg:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RelevantImg relevantImg)
    {
        startPage();
        List<RelevantImg> list = relevantImgService.selectRelevantImgList(relevantImg);
        return getDataTable(list);
    }

    /**
     * 导出相关图片列表
     */
    @RequiresPermissions("system:relevantimg:export")
    @Log(title = "相关图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RelevantImg relevantImg)
    {
        List<RelevantImg> list = relevantImgService.selectRelevantImgList(relevantImg);
        ExcelUtil<RelevantImg> util = new ExcelUtil<RelevantImg>(RelevantImg.class);
        return util.exportExcel(list, "relevantimg");
    }

    /**
     * 新增相关图片
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存相关图片
     */
    @RequiresPermissions("system:relevantimg:add")
    @Log(title = "相关图片", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RelevantImg relevantImg)
    {
        return toAjax(relevantImgService.insertRelevantImg(relevantImg));
    }

    /**
     * 修改相关图片
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        RelevantImg relevantImg = relevantImgService.selectRelevantImgById(id);
        mmap.put("relevantImg", relevantImg);
        return prefix + "/edit";
    }

    /**
     * 修改保存相关图片
     */
    @RequiresPermissions("system:relevantimg:edit")
    @Log(title = "相关图片", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RelevantImg relevantImg)
    {
        return toAjax(relevantImgService.updateRelevantImg(relevantImg));
    }

    /**
     * 删除相关图片
     */
    @RequiresPermissions("system:relevantimg:remove")
    @Log(title = "相关图片", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(relevantImgService.deleteRelevantImgByIds(ids));
    }
}
